<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('物料主数据列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="material-form">
                <div class="select-list">
                    <ul>
                        <li>
                            物料编码：<input name="code" type="text"/>
                        </li>
                        <li>
                            物料名称：<input name="name" type="text"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input class="time-input" id="startTime" name="params[beginTime]" placeholder="开始时间"
                                   type="text"/>
                            <span>-</span>
                            <input class="time-input" id="endTime" name="params[endTime]" placeholder="结束时间"
                                   type="text"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:material:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
               shiro:hasPermission="system:material:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:material:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:material:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary single disabled" onclick="viewMaterialVendor()"
               shiro:hasPermission="system:material:viewMaterialVendor">
                <i class="fa fa-edit"></i> 指定供应商
            </a>
            <a class="btn btn-primary single disabled" onclick="viewMaterialReplace()"
               shiro:hasPermission="system:material:viewMaterialReplace">
                <i class="fa fa-edit"></i> 维护替代料
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/material";

    $("#startTime").val(getDay(-14));
    $("#endTime").val(nowTime());

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "code",
            modalName: "物料编码",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    field: 'code',
                    title: '物料编码',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" shiro:hasPermission="system:material:detail" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'name',
                    title: '物料名称',
                    sortable: true
                },
                {
                    title: '物料类型',
                    field: 'type'
                },
                {
                    title: '单位',
                    field: 'unit'
                },
                {
                    title: '颜色',
                    field: 'color'
                },
                {
                    title: '启用批次管理',
                    field: 'batch'
                },
                {
                    title: '安全库存总数量',
                    field: 'safeStock'
                },
                {
                    title: '最大库存总量',
                    field: 'maxStock'
                },
                {
                    title: '重量',
                    field: 'weight'
                },
                {
                    title: '关联图纸',
                    field: 'associatedDrawingId'
                },
                {
                    title: '质检标记',
                    field: 'quality'
                },
                {
                    title: '审批状态',
                    field: 'auditStatus'
                },
                {
                    field: 'createBy',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'updateBy',
                    title: '修改人'
                },
                {
                    field: 'updateTime',
                    title: '修改时间',
                    sortable: true
                },
                {
                    title: '备注',
                    field: 'remark'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" shiro:hasPermission="system:material:viewMaterialVendor" href="javascript:void(0)" onclick="viewSuppliers(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看供应商</a> ');
                        actions.push('<a class="btn btn-success btn-xs" shiro:hasPermission="system:material:viewMaterialReplace" href="javascript:void(0)" onclick="viewSubstitutes(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看替代料</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    /*物料主数据-详细*/
    function detail(id) {
        var url = prefix + '/detail/' + id;
        $.modal.openFulls("物料明细", url);
    }

    /*指定供应商*/
    function viewMaterialVendor() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length !== 1) {
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        $.modal.openTab("指定供应商" + table.options.modalName, (prefix + "/viewMaterialVendor/{materialId}").replace('{materialId}', rows.join()));
    }

    /*维护替代料*/
    function viewMaterialReplace() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length !== 1) {
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        $.modal.openTab("指定供应商" + table.options.modalName, (prefix + "/viewMaterialReplace/{materialId}").replace('{materialId}', rows.join()));
    }

    /*查看供应商*/
    function viewSuppliers(id) {
        $.modal.openTab("指定供应商" + table.options.modalName, (prefix + "/viewMaterialVendor/{materialId}").replace('{materialId}', id));
    }

    /*查看替代料*/
    function viewSubstitutes(id) {
        $.modal.openTab("指定供应商" + table.options.modalName, (prefix + "/viewMaterialReplace/{materialId}").replace('{materialId}', id));
    }
</script>
</body>
</html>